package day_2022_7_to_8.day48;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/08/24 09:27
 **/
public class Day39_1_Num1460_CanBeEqual {
    class Solution {
        public boolean canBeEqual(int[] target, int[] arr) {
            if(target.length != arr.length) return false;
            Arrays.sort(target);
            Arrays.sort(arr);
            for(int i = 0; i < arr.length; ++i){
                if(target[i] != arr[i]) return false;
            }
            return true;
        }
    }
    class Solution1 {
        // 桶计数
        public boolean canBeEqual(int[] target, int[] arr) {
            if(target.length != arr.length) return false;
            int[] data = new int[10001];
            for(int i = 0; i < arr.length; ++i){
                data[target[i]]++;
                data[arr[i]]--;
            }
            for(int i : data){
                if(i != 0) return false;
            }
            return true;
        }
    }
}